package com.cndw.kungfu.model.goods.app;

import java.util.Map;

import com.cndw.kungfu.domain.Pet;
import com.cndw.kungfu.domain.Scene;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.model.Context;
/**
 * 使用宠物药品
 * @author fantadust [9677889@qq.com]
 * @date 2012-4-7 下午2:51:36
 */
public class AppDo112 extends AppBase {

	@Override
	public boolean check() throws Exception {
		
		Pet pet = player.getDataInfo().getPet();
		
		if (pet == null ) {
			throw new ErrPopException(LanguageLib.get("goods.use.nopet"));
		}	
		
		boolean isUse = false;
		if (goodsMode.getValueA() > 0 && pet.getHp() < pet.getMaxHp() ) {
			isUse = true;
		}
		if (goodsMode.getValueB() > 0 && pet.getMp() < pet.getMaxMp() ) {
			isUse = true;
		}	
		if (isUse == false) {			
			throw new ErrPopException(LanguageLib.get("goods.use.petfull"));			
		}
		Scene scene = Context.getSceneServer().getSceneById(player.getSceneId());
		if (scene != null && scene.isCityUnionWar()) {
			throw new ErrPopException(LanguageLib.get("goods.use.seige"));	
		}	
		
		return true;
	}

	@Override
	public Map<String, Object> run() throws Exception {
		
		Pet pet = player.getDataInfo().getPet();
		
		pet.alterHp(goodsMode.getValueA());
		pet.alterMp(goodsMode.getValueB());	
		
		msg.put("petHp", pet.getHp());
		msg.put("petMp", pet.getMp());
		
		return msg;
	}
}
